package com.example.studentims.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

//import javax.annotation.PostConstruct;
import jakarta.annotation.PostConstruct;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@Component
public class PhotoPathProvider { // 照片路径提供者，转换照片路径作用

    @Value("${photo.folder}")
    private String photoFolder;

    private Path absolutePath;

    @PostConstruct
    public void init() throws IOException {
        absolutePath = Paths.get(photoFolder).toAbsolutePath().normalize();
        if (!Files.exists(absolutePath)) {
            Files.createDirectories(absolutePath);
        }
        System.out.println("照片目录初始化：" + absolutePath);
    }

    public Path getPhotoPath() {
        return absolutePath;
    }

    public Path resolve(String subPath) {
        return absolutePath.resolve(subPath).normalize();
    }
}
